function gen_adv_caption_color()

local color = ""
  if Obj.where()== 2 then 
    color = "<label=spell_CapMAdvShop_font>"
  end
return color
end 

function advspell_parent_experience()

  Logic.hero_add_item( "hidden_parent_experience" )
  return true

end

function advspell_magic_stream()

  Logic.hero_add_item( "hidden_magic_stream" )
  return true

end

function advspell_mad_rage()

  Logic.hero_add_item( "hidden_mad_rage" )
  return true

end

function advspell_mind_depth()

  Logic.hero_add_item( "hidden_mind_depth" )
  return true

end

function advspell_titan_armor()

  Logic.hero_add_item( "hidden_titan_armor" )
  return true

end

function advspell_titan_sword()

  Logic.hero_add_item( "hidden_titan_sword" )
  return true

end

function advspell_flame_gaze()

  Logic.hero_add_item( "hidden_flame_gaze" )
  return true

end

function advspell_fortune_smile()

  Logic.hero_add_item( "hidden_fortune_smile" )
  return true

end

function advspell_giant_birth()

  -- local arr = { "ent", "peasant" }
  local arr = {}


  local hero = Logic.hero_lu_army()
  local i
  for i=1,7 do
    local atom, count = Logic.army_get(hero, i)
    if count == 0 then
      local hero_ld = Logic.hero_lu_item("leadership","count")

      -- loop to fill array with requred atoms
      for j=0,Logic.cp()-1 do

        atom = Logic.cp( j )
        if Logic.cp_level( atom ) == 5 then
          table.insert( arr, atom )
        end

      end

      local cnt
      repeat

        cnt = table.getn( arr )

        if cnt == 0 then
          return false
        end

        local index = Game.CurLocRand( cnt )
        atom = arr[ index + 1 ]

        local alead = Logic.cp_leadship( atom )
        cnt = math.floor( hero_ld / alead )

        if cnt == 0 or Logic.army_get(hero, atom) then
          table.remove( arr, index + 1 )
          cnt = 0
        end

      until cnt ~= 0

      Logic.hero_lu_army( Logic.army_add( hero, atom, cnt ) )
      Game.InvokeMsgBox("warning","<label=adv_troop_call><imu="..atom..".png><br=10><label=cpsn_"..atom..">: "..tostring(cnt))

      return true
    end
  end


  Game.InvokeMsgBox("warning","<label=by_not_enough_shit>")
  return false

end

function advspell_dead_outbreak()

  -- local arr = { "ent", "peasant" }
  local arr = {}


  local hero = Logic.hero_lu_army()
  local i
  for i=1,7 do
    local atom, count = Logic.army_get(hero, i)
    if count == 0 then
      local hero_ld = Logic.hero_lu_item("leadership","count")

      -- loop to fill array with requred atoms
      for j=0,Logic.cp()-1 do

        atom = Logic.cp( j )
        if Logic.cp_race( atom ) == "undead" and not string.find(atom,"bat") then
          table.insert( arr, atom )
        end

      end

      local cnt
      repeat

        cnt = table.getn( arr )

        if cnt == 0 then
          return false
        end

        local index = Game.CurLocRand( cnt )
        atom = arr[ index + 1 ]

        local alead = Logic.cp_leadship( atom )
        cnt = math.floor( hero_ld / alead )

        if cnt == 0 or Logic.army_get(hero, atom) then
          table.remove( arr, index + 1 )
          cnt = 0
        end

      until cnt ~= 0

      Logic.hero_lu_army( Logic.army_add( hero, atom, cnt ) )
      Game.InvokeMsgBox("warning","<label=adv_troop_call><imu="..atom..".png><br=10><label=cpsn_"..atom..">: "..tostring(cnt))
      return true
    end
  end


  Game.InvokeMsgBox("warning","<label=by_not_enough_shit>")
  return false

end

function advspell_wind_song()

	local arr = {"pirat","pirat2","sprite","sprite_lake","sunny_sprite","highterrant","griffin","griffin2","griffin_cursed","dryad","thunderbird","dragonfly_fire","dragonfly_lake","necrox","gorguana_avenger","gorguana_spirit","undead_brontor","undead_gobot","winged_shade"}

	local hero = Logic.hero_lu_army()
	local i
	for i=1,7 do
		local atom, count = Logic.army_get(hero, i)
		if count == 0 then
			local hero_ld = Logic.hero_lu_item("leadership","count")
			local cnt
			repeat
			cnt = table.getn( arr )
			if cnt == 0 then
				return false
			end
			local index = Game.CurLocRand( cnt )
			atom = arr[ index + 1 ]
			local alead = Logic.cp_leadship( atom )
			cnt = math.floor( hero_ld / alead )
			if cnt == 0 or Logic.army_get(hero, atom) then
				table.remove( arr, index + 1 )
				cnt = 0
			end
			until cnt ~= 0
			Logic.hero_lu_army( Logic.army_add( hero, atom, cnt ) )
			Game.InvokeMsgBox("warning","<label=adv_troop_call><imu="..atom..".png><br=10><label=cpsn_"..atom..">: "..tostring(cnt))
			return true
		end
	end
	Game.InvokeMsgBox("warning","<label=by_not_enough_shit>")
	return false
end

function adv_dur_true(spell)
  local itm=string.gsub(spell,"spell","hidden")
  if Obj.param(itm,"count")~=nil and Obj.param(itm,"count")~="" then return true end
  return false
end 

function gen_adv_duration()
	local time=0
	local spell=Obj.name()
  local itm=string.gsub(spell,"spell","hidden")
	if Obj.where()==0 then
        time=Obj.spell_level()
		return tostring(time)
	else 
  time=Obj.param(itm,"count")
		return tostring(time)
	end
end 